package com.example.springboot.controller;

import com.example.springboot.dao.UserRepository;
import com.example.springboot.entity.User;
import com.example.springboot.pojo.Animal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/10/10 22:10
 */
@RestController
public class UserController {
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private Animal animal;

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id") Integer id) {
        System.out.println(animal);
        Optional<User> optional = userRepository.findById(id);
        return optional.get();
    }

    @GetMapping("/user")
    public User insert(User user) {
        userRepository.save(user);
        return user;
    }
}
